/************************************************
 * Author       :   XXY
 * Blog         :   https://www.cnblogs.com/jzyl
 * Gitee        :   https://gitee.com/xiaobaichong
 * Email        :   1047185209@QQ.com
 * FileName     :   ColorUtility.cs
 * CreateData   :   2024/9/28 14:19:26
 * UnityVersion :   2021.3.30f1c1
 * Description  :   颜色实用工具
************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Main
{
    /// <summary>
    /// 颜色实用工具
    /// </summary>
    public static class ColorUtility
    {
        /// <summary>
        /// 将long存储的字段转化为颜色字段
        /// </summary>
        /// <returns>
        /// 32 位格式的 RGBA 颜色表示形式。每个颜色分量都是范围是 0 至 255 的字节值。
        /// </returns>
        public static Color32 LongToColor(long colorValue)
        {
            byte r = (byte)((colorValue & 0xff000000) >> 24);
            byte g = (byte)((colorValue & 0xff0000) >> 16);
            byte b = (byte)((colorValue & 0xff00) >> 8);
            byte a = (byte)((colorValue & 0xff));

            Color32 c = new Color32(r, g, b, a);
            return c;
        }
        /// <summary>
        /// 将颜色转化为long存储的字段
        /// </summary>
        /// <returns></returns>
        public static long ColorToLong(Color32 color)
        {
            return ((long)color.r << 24) | ((long)color.g << 16) | ((long)color.b << 8) | color.a;
        }
    }
}
